package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.dtos.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐控制器
 * @author ghy
 * @version v1.0
 * create on 2022/11/21 9:53
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 查询套餐信息：根据分类ID和状态
     * @param setmeal
     * @return
     */
    @GetMapping("/list")
    public R list(Setmeal setmeal){
        return setmealService.findList(setmeal);
    }


    /**
     * 根据ID列表删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public R deleteByIds(@RequestParam("ids") List<Long> ids){
        return setmealService.deleteByIds(ids);
    }

    /**
     * 分页条件查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    // /page?page=1&pageSize=10&name=%E5%A5%97%E9%A4%90
    @GetMapping("/page")
    public R page(Integer page, Integer pageSize, String name){
        return setmealService.findPage(page, pageSize, name);
    }


    /**
     * 新增
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R add(@RequestBody SetmealDto setmealDto){
        return setmealService.addWithDishes(setmealDto);
    }

}
